

package com.ljl.ningwei.mapper;

import com.ljl.ningwei.entity.Category;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * <p>
 * 分类表 Mapper 接口
 * </p>
 *
 * @author ljl
 * @since 2025-03-24
 */
public interface CategoryMapper {
    @Select("select " +
            "id as id,"+
            "name as name,"+
            "image_url as imageUrl,"+
            "parent_id as parentId,"+
            "create_time as createTime,"+
            "update_time as updateTime,"+
            "is_deleted as isDeleted "+
            "from category where id = #{id} and is_deleted = 0")
    Category getById(@Param("id") Long id);

    @Select("select " +
            "id as id,"+
            "name as name,"+
            "image_url as imageUrl,"+
            "parent_id as parentId,"+
            "create_time as createTime,"+
            "update_time as updateTime,"+
            "is_deleted as isDeleted "+
            "from category where id = #{id}")
    Category extractById(@Param("id") Long id);

    int update(Category category);


    int insert(Category category);

    @Update(" UPDATE category SET `is_deleted` = 1 WHERE  id = #{id}")
    int delete(@Param("id") Long id);

    @Select("select " +
            "id as id, "+
            "name as name, "+
            "image_url as imageUrl, "+
            "parent_id as parentId, "+
            "create_time as createTime, "+
            "update_time as updateTime, "+
            "is_deleted as isDeleted "+
            "from category " +
            "limit 999")
    List<Category> list();

    List<Category> listByIds(@Param("ids") String categoryIds);

    @Select("SELECT id FROM category WHERE `name` LIKE concat('%',#{name},'%')")
    List<Long> getIdsByName(@Param("name") String name);

    @Select("select " +
            "id as id, "+
            "name as name, "+
            "image_url as imageUrl, "+
            "parent_id as parentId, "+
            "create_time as createTime, "+
            "update_time as updateTime, "+
            "is_deleted as isDeleted "+
            "from category where parent_id = #{parentId} " +
            "limit 999")
    List<Category> listByParentId(@Param("parentId")Integer parentId);
}
